<?php
// +----------------------------------------------------------------------
// | PHP [ JUST YOU ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2017 http://www.jyphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: FlyingPig <flyingpigfp@163.com>
// +----------------------------------------------------------------------

namespace App\Console\Commands;


use App\Common\Tool;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class SetRandRoomRedis extends Command
{

    protected $signature = 'SetRandRoom';

    private $count = 0;

    public function handle()
    {
        Tool::redisInit();
//        $data = [];
//        for($x = 0;count($data) < 10000 ;$x++) {
//            $rand = $this->rand($data);
//            if (!empty($data[$rand])) {
//                dump("重复了".$x);
//                return;
//            }
//            $data[$rand] = 1;
//            Redis::rpush('rand_room_number',$rand);
//        }
//        echo '生成随机总数:'.count($data)."\n";
//        echo '生成成功'."\n";
//        echo '重复递归了'.$this->count.'次'."\n";
    }

    public function rand($data)
    {
        $rand = mt_rand(100000,1000000);
        if (!empty($data[$rand])) {
            $this->count += 1;
            return $this->rand($data);
        } else {
            return $rand;
        }
    }

}